package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.annotations.PolymorphismType;

import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Dept;
import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.Part;
import com.mes.basicdata.domain.Routing;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;

/**
 * <p>
 * Task实体.所有Task的基类.
 * </p>
 * 
 */
@Entity
@Table(name = "T_TASKS")
@BatchSize(size = 20)
@Lazy(value = true)

public class Task extends BasicModel {
	/**
	 *  越早越好
	 */
	public final static int CONSTRAINTTYPE_ASAP= 0; // 越早越好
	public final static int CONSTRAINTTYPE_ALAP= 1; // 越晚越好
	public final static int CONSTRAINTTYPE_MSO = 2; // 在限制日期开始
	public final static int CONSTRAINTTYPE_MFO = 3; // 在限制日期结束
	public final static int CONSTRAINTTYPE_SNET = 4; // 在限制日期或之后开始
	public final static int CONSTRAINTTYPE_SNLT = 5; // 在限制日期或之前开始
	public final static int CONSTRAINTTYPE_FNET = 6; // 在限制日期或之后完成
	public final static int CONSTRAINTTYPE_FNLT = 7; // 在限制日期或之前完成
	
	@Id
	@GenericGenerator(name = "taskUid", strategy = "assigned")
	@Column(name = "TASKUID")
	protected String taskUid;

	@Column(name = "TASKNAME")
	protected String taskName;
	
	// 任务号或者计划号
	@Column(name = "TASKID")
	protected String taskId;
	
	@Column(name = "PARENTUID")
	protected String parentTaskUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PARENTUID", insertable = false, updatable = false)
	protected Task parentTask;

	@Column(name="SCHEDULESTART")
	protected Date scheduleStart;
	
	@Column(name="SCHEDULEFINISH")
	protected Date scheduleFinish;
	
	@Column(name = "PLANSTART")
	protected Date planStart;

	@Column(name = "PLANFINISH")
	protected Date planFinish;

	@Column(name = "BASESTART")
	protected Date baseStart;

	@Column(name = "BASEFINISH")
	protected Date baseFinish;
	
	@Column(name="ACTUALSTART")
	protected Date actualStart;
	
	@Column(name="ACTUALFINISH")
	protected Date actualFinish;
	
	@Column(name="EARLYSTART")
	protected Date earlyStart;
	
	@Column(name="EARLYFINISH")
	protected Date earlyFinish;
	
	@Column(name="LATESTART")
	protected Date lateStart;
	
	@Column(name="LATEFINISH")
	protected Date lateFinish;
	
	@Column(name="CONSTRAINTTYPE")
	protected Integer constraintType;
	
	@Column(name="CONSTRAINTDATE")
	protected Date constraintDate;
	
	@Column(name = "TASKWORK")
	protected Float taskWork;
	
	@Column(name = "ESTITASKWORK")
	protected Float estiTaskWork;
	
	@Column(name = "COMPLETEWORK")
	protected Float completeWork;
	
	@Column(name="TASKTYPE")
	protected String taskType;
	
	@Column(name="TASKSTATE")
	protected Integer taskState;
	
	@Column(name="PRIORITY")
	protected Integer priority;
	
	@Column(name="COMPLETEPERCENT",precision=25,scale=6)
	protected Float completePercent;
	
	// 物料项
	@Column(name = "PART_NUMBER")
	protected String partUid;
	
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PART_NUMBER", insertable = false, updatable = false)
	protected Part part;
	
	// 型号
	@Column(name = "MODEL")
	protected String model;

	// 批次
	@Column(name = "BATCHNUM")
	protected String batchNum;

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getBatchNum() {
		return batchNum;
	}

	public void setBatchNum(String batchNum) {
		this.batchNum = batchNum;
	}

	public String getContignationNumber() {
		return contignationNumber;
	}

	public void setContignationNumber(String contignationNumber) {
		this.contignationNumber = contignationNumber;
	}

	public String getOperationIdDesc() {
		return operationIdDesc;
	}

	public void setOperationIdDesc(String operationIdDesc) {
		this.operationIdDesc = operationIdDesc;
	}

	public Float getPlanQty() {
		return planQty;
	}

	public void setPlanQty(Float planQty) {
		this.planQty = planQty;
	}

	public Float getCompleteQty() {
		return completeQty;
	}

	public void setCompleteQty(Float completeQty) {
		this.completeQty = completeQty;
	}

	// 架次号
	@Column(name = "CONTIGNATION_NUMBER")
	protected String contignationNumber;

	// 工序号
	@Column(name = "OPERATION_IDDESC")
	protected String operationIdDesc;
		
	// 在制数
	@Column(name="PLANQTY")
	protected Float planQty;
	
	// 完成数
	@Column(name="COMPLETEQTY")
	protected Float completeQty;
	
	
	
	/**
	 * 空的构造函数
	 */
	public Task() {

	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.taskUid;
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getTaskUid();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setTaskUid(uuid);
	}

	public String getTaskUid() {
		return taskUid;
	}

	public void setTaskUid(String taskUid) {
		this.taskUid = taskUid;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public String getParentTaskUid() {
		return parentTaskUid;
	}

	public void setParentTaskUid(String parentTaskUid) {
		this.parentTaskUid = parentTaskUid;
	}

	public Task getParentTask() {
		return parentTask;
	}

	public void setParentTask(Task parentTask) {
		this.parentTask = parentTask;
	}

	/**
	 * 获取排产任务工时
	 * 
	 * @return
	 */
	
	public Float getEstiTaskWork() {
		return estiTaskWork;
	}

	/**
	 * 设置排产任务工时
	 * 
	 * @param estitaskwork
	 */
	public void setEstiTaskWork(Float estiTaskWork) {
		this.estiTaskWork = estiTaskWork;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	public Date getScheduleStart() {
		return scheduleStart;
	}

	public void setScheduleStart(Date scheduleStart) {
		this.scheduleStart = scheduleStart;
	}

	public Date getScheduleFinish() {
		return scheduleFinish;
	}

	public void setScheduleFinish(Date scheduleFinish) {
		this.scheduleFinish = scheduleFinish;
	}

	public Date getPlanStart() {
		return planStart;
	}

	public void setPlanStart(Date planStart) {
		this.planStart = planStart;
	}

	public Date getPlanFinish() {
		return planFinish;
	}

	public void setPlanFinish(Date planFinish) {
		this.planFinish = planFinish;
	}

	public Date getBaseStart() {
		return baseStart;
	}

	public void setBaseStart(Date baseStart) {
		this.baseStart = baseStart;
	}

	public Date getBaseFinish() {
		return baseFinish;
	}

	public void setBaseFinish(Date baseFinish) {
		this.baseFinish = baseFinish;
	}

	public Date getActualStart() {
		return actualStart;
	}

	public void setActualStart(Date actualStart) {
		this.actualStart = actualStart;
	}

	public Date getActualFinish() {
		return actualFinish;
	}

	public void setActualFinish(Date actualFinish) {
		this.actualFinish = actualFinish;
	}

	public Date getEarlyStart() {
		return earlyStart;
	}

	public void setEarlyStart(Date earlyStart) {
		this.earlyStart = earlyStart;
	}

	public Date getEarlyFinish() {
		return earlyFinish;
	}

	public void setEarlyFinish(Date earlyFinish) {
		this.earlyFinish = earlyFinish;
	}

	public Date getLateStart() {
		return lateStart;
	}

	public void setLateStart(Date lateStart) {
		this.lateStart = lateStart;
	}

	public Date getLateFinish() {
		return lateFinish;
	}

	public void setLateFinish(Date lateFinish) {
		this.lateFinish = lateFinish;
	}

	public Integer getConstraintType() {
		return constraintType;
	}

	public void setConstraintType(Integer constraintType) {
		this.constraintType = constraintType;
	}

	public Date getConstraintDate() {
		return constraintDate;
	}

	public void setConstraintDate(Date constraintDate) {
		this.constraintDate = constraintDate;
	}

	public Float getTaskWork() {
		return taskWork;
	}

	public void setTaskWork(Float taskWork) {
		this.taskWork = taskWork;
	}

	public Float getCompleteWork() {
		return completeWork;
	}

	public void setCompleteWork(Float completeWork) {
		this.completeWork = completeWork;
	}

	public String getTaskType() {
		return taskType;
	}

	public void setTaskType(String taskType) {
		this.taskType = taskType;
	}

	public Integer getTaskState() {
		return taskState;
	}

	public void setTaskState(Integer taskState) {
		this.taskState = taskState;
	}

	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	public Float getCompletePercent() {
		return completePercent;
	}

	public void setCompletePercent(Float completePercent) {
		this.completePercent = completePercent;
	}

	public String getPartUid() {
		return partUid;
	}

	public void setPartUid(String partUid) {
		this.partUid = partUid;
	}

	public Part getPart() {
		return part;
	}

	public void setPart(Part part) {
		this.part = part;
	}


	/**
	 * 大纲级别，用于设置优先级 hba
	 * aad by lcs 用于AO任务管理优先级展示
	 */
	@Column(name = "OUTLINELEVEL")
	protected String outLineLevel;

	public String getOutLineLevel() {
		return outLineLevel;
	}

	public void setOutLineLevel(String outLineLevel) {
		this.outLineLevel = outLineLevel;
	}
	
}